package com.demo.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T>  {
    private Integer status;
    private String msg;
    private T data;
    private Long total;

    public static Result<Void> ok(){
        return new Result<>(200, null, null, null);
    }
    public static <T> Result<T> ok(T data){
        return new Result<>(200, null, data, null);
    }
    public static <T> Result<T> ok(T data, String msg){
        return new Result<>(200, msg, data, null);
    }
    public static <R> Result<List<R>> ok(List<R> data, int total){
        return new Result<>(200, null, data, (long) total);
    }
    public static <T> Result<T> fail(String errorMsg){
        return new Result<>(400, errorMsg, null, null);
    }
}
